package com.hangzhou.xyj.ui.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.hangzhou.xyj.ui.fragment.CityIntrerestFragment;
import com.hangzhou.xyj.ui.fragment.DramaDynamicsFragment;
import com.hangzhou.xyj.ui.fragment.FollowDynamicsFragment;
import com.hangzhou.xyj.ui.fragment.base.BaseFragment;

/**
 * Created by neo.duan on 2015/12/23.
 * 社群ViewPager的Fragment Adapter
 */
public class HomeCommunityVPAdapter extends FragmentPagerAdapter {
    private final String[] mTitles = {
            "曲目动态",
            "关注动态",
            "同城同好",
    };
    public FollowDynamicsFragment mFollowFragment;
    private DramaDynamicsFragment mDramaFragment;
    private CityIntrerestFragment mCityFragment;

    public HomeCommunityVPAdapter(FragmentManager fm) {
        super(fm);
    }


    @Override
    public Fragment getItem(int position) {
        BaseFragment fragment = null;
        switch (position) {
            case 0:
                if (mDramaFragment == null) {
                    mDramaFragment = new DramaDynamicsFragment();
                }
                fragment = mDramaFragment;
                break;
            case 1:
                if (mFollowFragment == null) {
                    mFollowFragment = new FollowDynamicsFragment();
                }
                fragment = mFollowFragment;
                break;
            case 2:
            default:
                if (mCityFragment == null) {
                    mCityFragment = new CityIntrerestFragment();
                }
                fragment = mCityFragment;
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //不需要destroy item
    }
}
